package com.atxyj.springsecurity.system.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.Instant;

/**
 * @author xieyujiao
 * @description
 * @date 2021/7/30
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass //泛化:继承关系。告诉JPA这是所有类都继承的父类。将实体类作为基类实体，不会映射到数据库表
@EntityListeners(value = AuditingEntityListener.class)
public abstract class AbstractAuditBase {

    @CreatedDate
    @Column(updatable = false) //当修改或插入时，保证数据不传入，这个字段不被更新，保持原值
    @JsonIgnore //在实体类向前台返回数据时用来忽略不想传递给前台的属性或接口。
    private Integer createdAt;

    @LastModifiedDate
    @JsonIgnore
    private Instant updatedAt;

    @CreatedBy
    @Column(updatable = false)
    @JsonIgnore
    private String createdBy;

    @LastModifiedBy
    @JsonIgnore
    private String updatedBy;


}
